<?php
/**
 * @copyright   Copyright (c) 2017 https://www.sapixx.com All rights reserved.
 * @license     Licensed (http://www.apache.org/licenses/LICENSE-2.0).
 * @author      pillar<ltmn@qq.com>
 * 商家和商圈关联表
 */
namespace app\ais\model;
use think\model\Pivot;

class AisStoreUnion extends Pivot{
    
    //加入的群组
    public function group(){
        return $this->hasOne('AisStoreGroup','id','group_id');
    }

    //加入的群组
    public function store(){
        return $this->hasOne('AisStore','id','store_id');
    }

    //是否圈主
    public static function isGroup($store_id,$store_id_two,$member_miniapp_id){
        $group_ids = self::where(['member_miniapp_id'=> $member_miniapp_id,'store_id' => $store_id,'type' => 0])->column('group_id');
        $list = self::where(['member_miniapp_id'=> $member_miniapp_id,'store_id' => $store_id_two,'type' => 0])->whereIn('group_id',$group_ids)->column('group_id');
        if(!$list){
            return false;
        }
        return implode(",",$list);
    }
}